from machine import Pin,PWM
import time
servo_pin = 11

servo=PWM(Pin(servo_pin),freq=50)
servo.duty(77)
time.sleep(1)
servo.duty(122)

up_pin=12
ups = PWM(Pin(up_pin),freq=50)
time.sleep(1)

ups.duty(77)
time.sleep(1)
ups.duty(122)

try:  
    while True:  
        # 循环调整占空比，控制舵机旋转角度  
        for i in range(77, 122):  
            servo.duty(i)  # 设置占空比为i * 1000  
            time.sleep(1)  # 等待一段时间，以便舵机能够响应  
            ups.duty(i)  # 设置占空比为i * 1000  
            time.sleep(1)  # 等待一段时间，以便舵机能够响应  
except KeyboardInterrupt:  
    # 按下Ctrl+C时停止PWM输出  
    pwm.deinit()

x = 122
y = 122
revx = False
revy = False

while True:
    if x > 122:
        revx = True
    elif x < 80:
        revx = False
    if revx:
        x = x - 5
    else:
        x = x + 5
    servo.duty(x)
    time.sleep(1)
